import { TAB_LOADING_TEXT } from '@/constants';
import { useTabs } from 'vc/src/web/multiple-tabs/use';

/** tab title 的变化 */
export function useTitle (loading, data, route) {
  const { setTitle, getTitle } = useTabs();
  watch(() => [loading.value || data.value], () => {
    if (getTitle(route) && getTitle(route) !== TAB_LOADING_TEXT) {
      return;
    }
    setTitle(data.value?.name || TAB_LOADING_TEXT, route);
  }, {
    immediate: true,
    deep: true
  });
}
